#include "NoResourceFile.h"


NoResourceFile::NoResourceFile(std::string location)
{
	m_FileName = location;
	if(!VOpen())
	{
		assert(0 && "Could not open the requested file.");
	}
}
NoResourceFile::~NoResourceFile()
{
	if(m_file.is_open())
	{
		m_file.close();
	}
}

bool NoResourceFile::VOpen()
{
	m_file.open(m_FileName, std::ios::binary);
	if(!m_file.is_open())
	{
		return false;
	}
	//get the file size
	m_file.seekg(0, std::ios::end);
	file_len = m_file.tellg();
	m_file.seekg(0, std::ios::beg); // return the ptr to the begin
	return true;
}
const std::string NoResourceFile::VGetFilename()
{
	return m_FileName;
}
unsigned int NoResourceFile::VGetResourceSize(const Resource &res)
{
	if(VFileExist(m_FileName) && m_file.is_open()) // if it is not open->something failed at init and file_len is empty
	{
		return file_len;
	}
	return 0;
}

void NoResourceFile::VGetResource( const Resource &res, char * buffer)
{
	if(!(VFileExist(m_FileName) && m_file.is_open()))
	{
		return;
	}
	m_file.read(buffer,file_len);
	m_file.seekg(0, std::ios::beg); // make sure we've got default state again
}

bool NoResourceFile::VFileExist(const std::string & filename)
{
	if(filename == m_FileName)
	{
		return true;
	}
	return false;
}